import { GSprite } from "../../../../../../com/mui/controls/GSprite";
import { ObjCreate } from "../../../common/ObjCreate";
import { ImagesConst } from "../../../../resource/ImagesConst";
import { GTextFormat } from "../../../../../common/GTextFormat";
import { FontUtil } from "../../../../../common/font/FontUtil";
import { Language } from "../../../../../../extend/language/Language";
import { GuildEliteGroupMemberRenderer } from "./GuildEliteGroupMemberRenderer";
import { SGuildGroupPlayer } from "../../../../../../Message/Public/SGuildGroupPlayer";
import { EGuildGroupPos } from "../../../../../../Message/Public/EGuildGroupPos";
import { Cache } from "../../../../cache/Cache";
import { EntityUtil } from "../../../../scene/layer/utils/EntityUtil";
import { DataEvent } from "../../../../events/DataEvent";
import { GModuleEvent } from "../../../../mvc/GModuleEvent";
import { DataProvider } from "../../../../../../fl/data/DataProvider";
import { GTileList } from "../../../../../../com/mui/controls/GTileList";
import { GButton } from "../../../../../../com/mui/controls/GButton";
type int = number;
//class GuildEliteGroupGroup
    
    export  class GuildEliteGroupGroup extends GSprite
    {
        constructor(arg1: int)
        {
            super();
            this._index = arg1;
            this.initUI();
            return;
        }

        public get index(): int
        {
            return this._index;
        }

        /* internal  */initUI(): void
        {
            ObjCreate.createBg(0, 0, 242, 177, this, ImagesConst.DisabledBg);
            ObjCreate.createBg(10, 3, 222, 22, this, ImagesConst.Friend_over);
            var loc1=new GTextFormat(FontUtil.stXingkaiName, 16, 16776960, true);
            ObjCreate.createGTextField(Language.getStringByParam(60651, this._index), 10, 5, 200, 25, this, loc1, true, false);
            loc1.font = FontUtil.defaultName;
            loc1.size = 12;
            loc1.bold = false;
            loc1.color = 16777215;
            ObjCreate.createGTextField(Language.getString(60652), 25, 27, 100, 20, this, loc1);
            ObjCreate.createGTextField(Language.getString(60653), 128, 27, 100, 20, this, loc1);
            ObjCreate.createGTextField(Language.getString(60654), 167, 27, 100, 20, this, loc1);
            this._memberList = ObjCreate.createTileList(0, 49, 242, 120, this);
            this._memberList.columnWidth = 240;
            this._memberList.rowHeight = 24;
            this._memberList.setStyle("cellRenderer", GuildEliteGroupMemberRenderer);
            this._memberList.addEventListener(flash.events.Event.CHANGE, this.onSelectedChangeHandler);
            this._optBtn = ObjCreate.createGButton(Language.getString(60674), 186, 3, 49, 22, this);
            this._optBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOptBtnClickHandler);
            this._optBtn.visible = false;
            return;
        }

        public set selectedIndex(arg1: int)
        {
            this._memberList.selectedIndex = arg1;
            this.updateOptBtnState();
            return;
        }

        public set selectedMember(arg1: SGuildGroupPlayer)
        {
            this._memberList.selectedItem = arg1;
            this.updateOptBtnState();
            return;
        }

        /* internal  */updateOptBtnState(): void
        {
            this._optBtn.visible = this.showOptButton();
            return;
        }

        /* internal  */showOptButton(): Boolean
        {
            if (this._memberList.selectedItem == null) 
            {
                return false;
            }
            if (this.selectedMember.postion == EGuildGroupPos._EGuildGroupCaptain) 
            {
                return false;
            }
            if (Cache.instance.guild.isLeaderOrDeputyLeader || this.isIamTheCaptain()) 
            {
                return true;
            }
            return false;
        }

        /* internal  */isIamTheCaptain(): Boolean
        {
            var loc2=null;
            var loc1=Cache.instance.role.entityInfo.entityId;
            var loc3=0;
            while (loc3 < this._memberList.dataProvider.length) 
            {
                loc2 = this._memberList.dataProvider.getItemAt(loc3) as SGuildGroupPlayer;
                if (loc2 && EntityUtil.equal(loc2.player.entityId, loc1)) 
                {
                    return loc2.postion == EGuildGroupPos._EGuildGroupCaptain;
                }
                ++loc3;
            }
            return false;
        }

        public get selectedMember(): SGuildGroupPlayer
        {
            return this._memberList.selectedItem as SGuildGroupPlayer;
        }

        /* internal  */onOptBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.dispatchEvent(new DataEvent(GModuleEvent.GuildGroup_ModifyTeamLeader));
            return;
        }

        public updateDataProvider(arg1: DataProvider): void
        {
            this._memberList.dataProvider = arg1;
            if (arg1.length == 0) 
            {
                return;
            }
            if (this._memberList.selectedIndex >= 0 && this._memberList.selectedItem == null) 
            {
                this._memberList.selectedIndex = -1;
                this.onSelectedChangeHandler(null);
            }
            return;
        }

        /* internal  */onSelectedChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this.dispatchEvent(new DataEvent(GModuleEvent.GuildGroup_MemberSelectedChange, this._memberList.selectedItem, false, true, true));
            return;
        }

        /* internal */ /* var */_index: int;

        /* internal */ /* var */_memberList: GTileList;

        /* internal */ /* var */_optBtn: GButton;
    }
